﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 药品信息管理
{
    public partial class YP_KCYJ : Form
    {
        DataTable dt = new DataTable();
        public YP_KCYJ()
        {
            InitializeComponent();
        }

        private void KC_show()
        {
            DataGridViewTextBoxColumn c = new DataGridViewTextBoxColumn();
            try
            {
                using (SqlConnection con = new SqlConnection(SQL.connectDB))
                {

                    SqlCommand sc = con.CreateCommand();//使用connection对象创建SqlCommand对象
                    SqlDataAdapter da = new SqlDataAdapter();//实例化sqldataadpte
                    SqlCommand cmd1 = new SqlCommand("SELECT * FROM ZD_YPJB", con);//sql语句
                    da.SelectCommand = cmd1;//设置为已实例化SqlDataAdapter的查询命令
                    da.Fill(dt);
                    //DataRow dqkc = new DataRow();
                    DataColumn dqkc1 = new DataColumn();
                    dqkc1.ColumnName = "当前库存";
                    dt.Columns.Add(dqkc1);
                    for (int i = 0; i < dt.Rows.Count; i++)
                        dt.Rows[i][3] = Convert.ToInt16(dt.Rows[i][0]) - Convert.ToInt16(dt.Rows[i][2]);
                    // dt.Rows.Add()
                    dataGridViewX1.DataSource = dt;
                    dataGridViewX1.Columns[0].HeaderText = "编码";
                    dataGridViewX1.Columns[1].HeaderText = "级别名称";
                    dataGridViewX1.Columns[2].HeaderText = "标记";
                    dataGridViewX1.Columns[1].Width = 180;
                    c.HeaderText = "当前库存";
                    c.Name = "cc";
                    dataGridViewX1.Columns.Add(c);


                    //dataGridViewX1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader;//自动根据内容调整列宽
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
 
        }
        private void YP_KCYJ_Load(object sender, EventArgs e)
        {

            KC_show();
        }

        private void XLGL_ALL_CheckedChanged(object sender, EventArgs e)
        {
            
        }
    }
}